﻿/********************************************************************
created:	2009/11/16
created:	09:10:2009   9:10
filename: 	GlobalDefine.h
author:		XinPing Huang
email:		77967292@qq.com
Qualifier:  常用的头文件、宏和类
*********************************************************************/
#ifndef GLOBAL_H_FILE
#define GLOBAL_H_FILE
#pragma once
extern "C"
{
#include "script/lua.h"
#include "script/lualib.h"
#include "script/lauxlib.h"
}
#include "HLuaScript.h"
#pragma comment(lib,"lib/lua5.1.lib")

//计算数组维数
#define SafeCountArray(Array) (sizeof(Array)/sizeof(Array[0]))
//计算字符长度
#define SafeCountString(String) ((UINT)((lstrlen(String)+1)*sizeof(TCHAR)))
//安全删除指针
#define  SafeDelete(pData)	{ try { delete pData; } catch (...) { } pData=NULL; } 
//安全删除指针数组
#define  SafeDeleteArray(pData)	{ try { delete [] pData; } catch (...) { } pData=NULL; } 
//安全new对象
#define SafeNew(pData) { if(pData) { delete pData;} new pData; }
//安全释放对象
#define SafeRelease(p)		{ if(p) { (p)->Release(); (p) = NULL; } }


//	--------------------------------------------------------------------------
#define DATE_TIME_FORMAT	_T("%Y-%m-%d %H:%M:%S")
#define DATE_FORMAT			_T("%Y-%m-%d")
#define TIME_FORMAT			_T("%H:%M:%S")
#define DATE_FORMAT_SLASH	_T("%Y/%m/%d")
//	--------------------------------------------------------------------------
#define STR_TRUE	_T("1")
#define STR_FALSE	_T("0")
#define CHAR_TRUE	_T('1')
#define CHAR_FALSE	_T('0')
#define STR_EMPTY	_T("")
#define	CHAR_END	_T('\0')
//	--------------------------------------------------------------------------
#define ADD_FLAG(dwFlags, dwAddFlag)	{	\
	dwFlags |= dwAddFlag;					\
}
#define REMOVE_FLAG(dwFlags, dwRemoveFlag)	{	\
	dwFlags &= ~dwRemoveFlag;					\
}
#define MODIFY_FLAG(bAdded, dwFlags, dwModifyFlag)	{	\
	if (bAdded){ADD_FLAG(dwFlags, dwModifyFlag);}		\
	else	{REMOVE_FLAG(dwFlags, dwModifyFlag);}		\
}
#define FLAG_IS_VALID(dwFlags, dwCheckFlag)	((dwFlags & dwCheckFlag) == dwCheckFlag)

#endif